clear all

*set working directory
use "Study 2 data.dta"


*coding MF scores

*health
gen rel_harm1=(rel_health_1 + rel_health_2 + rel_health_3)/3
gen rel_fair1=(rel_health_4 + rel_health_5 + rel_health_6)/3
gen rel_patr1=(rel_health_7 + rel_health_8 + rel_health_9)/3
gen rel_auth1=(rel_health_10 + rel_health_11 + rel_health_12)/3

*poverty
gen rel_harm2=(rel_poverty_1 + rel_poverty_2 + rel_poverty_3)/3
gen rel_fair2=(rel_poverty_4 + rel_poverty_5 + rel_poverty_6)/3
gen rel_patr2=(rel_poverty_7 + rel_poverty_8 + rel_poverty_9)/3
gen rel_auth2=(rel_poverty_10 + rel_poverty_11 + rel_poverty_12)/3

*enviro
gen rel_harm3=(rel_enviro_1 + rel_enviro_2 + rel_enviro_3)/3
gen rel_fair3=(rel_enviro_4 + rel_enviro_5 + rel_enviro_6)/3
gen rel_patr3=(rel_enviro_7 + rel_enviro_8 + rel_enviro_9)/3
gen rel_auth3=(rel_enviro_10 + rel_enviro_11 + rel_enviro_12)/3

*combining dem-owned issues
egen dem_harm=rowfirst(rel_harm1 rel_harm2 rel_harm3)
egen dem_fair=rowfirst(rel_fair1 rel_fair2 rel_fair3)
egen dem_patr=rowfirst(rel_patr1 rel_patr2 rel_patr3)
egen dem_auth=rowfirst(rel_auth1 rel_auth2 rel_auth3)

egen demcomp=rowfirst(trait_health_1 trait_poverty_1 trait_enviro_1)
egen demfair=rowfirst(trait_health_2 trait_poverty_2 trait_enviro_2)
egen demtoug=rowfirst(trait_health_3 trait_poverty_3 trait_enviro_3)
egen dempatr=rowfirst(trait_health_4 trait_poverty_4 trait_enviro_4)
egen deminte=rowfirst(trait_health_5 trait_poverty_5 trait_enviro_5)

*crime
gen rel_harm4=(rel_crime_1 + rel_crime_2 + rel_crime_3)/3
gen rel_fair4=(rel_crime_4 + rel_crime_5 + rel_crime_6)/3
gen rel_patr4=(rel_crime_7 + rel_crime_8 + rel_crime_9)/3
gen rel_auth4=(rel_crime_10 + rel_crime_11 + rel_crime_12)/3

*terror
gen rel_harm5=(rel_terror_1 + rel_terror_2 + rel_terror_3)/3
gen rel_fair5=(rel_terror_4 + rel_terror_5 + rel_terror_6)/3
gen rel_patr5=(rel_terror_7 + rel_terror_8 + rel_terror_9)/3
gen rel_auth5=(rel_terror_10 + rel_terror_11 + rel_terror_12)/3

*security
gen rel_harm6=(rel_security_1 + rel_security_2 + rel_security_3)/3
gen rel_fair6=(rel_security_4 + rel_security_5 + rel_security_6)/3
gen rel_patr6=(rel_security_7 + rel_security_8 + rel_security_9)/3
gen rel_auth6=(rel_security_10 + rel_security_11 + rel_security_12)/3

*combining rep-owned issues
egen rep_harm=rowfirst(rel_harm4 rel_harm5 rel_harm6)
egen rep_fair=rowfirst(rel_fair4 rel_fair5 rel_fair6)
egen rep_patr=rowfirst(rel_patr4 rel_patr5 rel_patr6)
egen rep_auth=rowfirst(rel_auth4 rel_auth5 rel_auth6)

egen repcomp=rowfirst(trait_crime_1 trait_terror_1 trait_security_1)
egen repfair=rowfirst(trait_crime_2 trait_terror_2 trait_security_2)
egen reptoug=rowfirst(trait_crime_3 trait_terror_3 trait_security_3)
egen reppatr=rowfirst(trait_crime_4 trait_terror_4 trait_security_4)
egen repinte=rowfirst(trait_crime_5 trait_terror_5 trait_security_5)


*renaming traits
rename trait_health_1 comp1
rename trait_health_2 fair1
rename trait_health_3 patr1
rename trait_health_4 toug1
rename trait_health_5 inte1

rename trait_poverty_1 comp2
rename trait_poverty_2 fair2
rename trait_poverty_3 patr2
rename trait_poverty_4 toug2
rename trait_poverty_5 inte2

rename trait_enviro_1 comp3
rename trait_enviro_2 fair3
rename trait_enviro_3 patr3
rename trait_enviro_4 toug3
rename trait_enviro_5 inte3

rename trait_crime_1 comp4
rename trait_crime_2 fair4
rename trait_crime_3 patr4
rename trait_crime_4 toug4
rename trait_crime_5 inte4

rename trait_terror_1 comp5
rename trait_terror_2 fair5
rename trait_terror_3 patr5
rename trait_terror_4 toug5
rename trait_terror_5 inte5

rename trait_security_1 comp6
rename trait_security_2 fair6
rename trait_security_3 patr6
rename trait_security_4 toug6
rename trait_security_5 inte6


*combining traits for rep-owned issues
egen comp_rep=rowfirst(comp4 comp5 comp6)
egen fair_rep=rowfirst(fair4 fair5 fair6)
egen patr_rep=rowfirst(patr4 patr5 patr6)
egen toug_rep=rowfirst(toug4 toug5 toug6)
egen inte_rep=rowfirst(inte4 inte5 inte6)

*combining traits for dem-owned issues
egen comp_dem=rowfirst(comp1 comp2 comp3)
egen fair_dem=rowfirst(fair1 fair2 fair3)
egen patr_dem=rowfirst(patr1 patr2 patr3)
egen toug_dem=rowfirst(toug1 toug2 toug3)
egen inte_dem=rowfirst(inte1 inte2 inte3)


*recoding party issue handling evaluations
rename owndem_1 owndem3
rename owndem_2 owndem2
rename owndem_3 owndem1
rename owndem_4 owndem6
rename owndem_5 owndem5
rename owndem_6 owndem4
rename ownrep_1 ownrep3
rename ownrep_2 ownrep2
rename ownrep_3 ownrep1
rename ownrep_4 ownrep6
rename ownrep_5 ownrep5
rename ownrep_6 ownrep4

*creating comparative issue handling 
forval x=1/6 {
gen owndiff`x' = ownrep`x' - owndem`x'
}



*recoding issue-level ideology
rename issueideo_1 issueideo3
rename issueideo_2 issueideo2
rename issueideo_3 issueideo1
rename issueideo_4 issueideo6
rename issueideo_5 issueideo5
rename issueideo_6 issueideo4
egen issueideorep=rowfirst(issueideo4 issueideo5 issueideo6)
egen issueideodem=rowfirst(issueideo1 issueideo2 issueideo3)



************
* analysis *
************

*foundation scores by issue type
ttest rep_harm=dem_harm
ttest rep_fair=dem_fair
ttest rep_patr=dem_patr
ttest rep_auth=dem_auth

*trait importance by issue type
ttest comp_rep=comp_dem
ttest fair_rep=fair_dem
ttest toug_rep=toug_dem
ttest patr_rep=patr_dem
ttest inte_rep=inte_dem

*Figure 3. Differences in moral priorities
gen x=.
replace x=5 in 1
replace x=4 in 2
replace x=3 in 3
replace x=2 in 4
replace x=1 in 5

gen x2=.
replace x2=4 in 1
replace x2=3 in 2
replace x2=2 in 3
replace x2=1 in 4

gen fe=.
gen fhi=.
gen flo=.

*foundations
ttest rep_harm=dem_harm
replace fe=r(mu_1) - r(mu_2) in 1
replace fhi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 1
replace flo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 1
ttest rep_fair=dem_fair
replace fe=r(mu_1) - r(mu_2) in 2
replace fhi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 2
replace flo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 2
ttest rep_patr=dem_patr
replace fe=r(mu_1) - r(mu_2) in 3
replace fhi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 3
replace flo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 3
ttest rep_auth=dem_auth
replace fe=r(mu_1) - r(mu_2) in 4
replace fhi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 4
replace flo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 4

*traits
gen te=.
gen thi=.
gen tlo=.
ttest comp_rep=comp_dem
replace te=r(mu_1) - r(mu_2) in 1
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 1
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 1
ttest fair_rep=fair_dem
replace te=r(mu_1) - r(mu_2) in 2
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 2
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 2
ttest patr_rep=patr_dem
replace te=r(mu_1) - r(mu_2) in 3
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 3
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 3
ttest toug_rep=toug_dem
replace te=r(mu_1) - r(mu_2) in 4
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 4
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 4
ttest inte_rep=inte_dem
replace te=r(mu_1) - r(mu_2) in 5
replace thi=(r(mu_1) - r(mu_2)) + 1.96*r(se) in 5
replace tlo=(r(mu_1) - r(mu_2)) - 1.96*r(se) in 5

twoway (scatter x2 fe, msize(medium) msym(0) mcol(gs10)) (rcap flo fhi x2, lwidth(medthick) lcol(gs10) horiz xline(0) legend(off) ///
	xtitle("Difference in relevance (R - D)") ysc(range(.5 4.5)) ytitle("") ///
	ylab(4 "Care" 3 "Fairness" 2 "Loyalty" 1 "Authority") xlab(-1(.5)1.5) ///
	subtitle("Moral Relevance") saving(relown.gph, replace))

twoway (scatter x te, msize(medium) msym(0) mcol(gs10)) (rcap tlo thi x, lwidth(medthick) lcol(gs10) horiz xline(0) legend(off) ///
	xtitle("Difference in importance (R - D)") ysc(range(0.5 5.5)) ytitle("") ///
	ylab(5 "Compassion" 4 "Fair-minded" 3 "Patriotic" 2 "Tough" 1 "Intelligent") ///
	subtitle("Trait Importance (Closed)") xlab(-1(.5)1.5) saving(traitown.gph, replace))


	
*************
* Reshaping *
*************

drop issueideo_DO

reshape long owndiff issueideo rel_harm rel_fair rel_patr rel_auth comp fair patr toug inte, i(ID) j(issue)

xtset ID

*averaging foundations 
gen indavg = (rel_harm+rel_fair)/2
gen bindavg = (rel_patr + rel_auth)/2
gen indtrait=(comp+fair)/2
gen bindtrait=(toug+patr)/2

*predicting ownership by foundation relevance, trait importance
xtreg owndiff indavg bindavg i.issue, fe vce(cluster ID)
est store rel2
xtreg owndiff indtrait bindtrait inte i.issue, fe vce(cluster ID)
est store trait3

*figure 4 
coefplot rel2, ciopts(lwidth(medthick) lcol(black)) msize(medium) msym(0) mcol(black) keep(indavg bindavg) xline(0) xlab(-.6(.2).6) ///
	rename(indavg="Care & Fairness" bindavg="Authority & Loyalty") ///
	subtitle("Moral Relevance") ///
	xtitle("Effect on Relative Party Handling (R - D)", size(small)) ///
	saving(foundationeffects.gph, replace)
coefplot trait3, ciopts(lwidth(medthick) lcol(black)) msize(medium) msym(0) mcol(black) keep(indtrait bindtrait inte) xline(0) xlab(-.6(.2).6) ///
	coeflabels(indtrait=`""Compassionate" "& Fair-minded""' bindtrait=`""Tough &" "Patriotic""' inte="Intelligent") ///
	subtitle("Trait Importance (Closed)") ///
	xtitle("Effect on Relative Party Handling (R - D)", size(small)) ///
	saving(traiteffects.gph, replace)

*robustness to issue-level ideology
xtreg owndiff indavg bindavg issueideo i.issue, fe vce(cluster ID)
xtreg owndiff indtrait bindtrait inte issueideo i.issue, fe vce(cluster ID)
